package com.function;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class GetPublicIPAddress {

    public static void main(String[] args) {
        try {
            URL url = new URL("http://checkip.amazonaws.com");
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            String ipAddress = br.readLine().trim();
            System.out.println("Public IP Address: " + ipAddress);
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
